<template>
	<view class="box">
		<view class="box1" v-for="item in xttells" :key="item.announcementId">
			<view class="top">
				<text>{{happenTimeFun(item.announcementCreateTime)}}</text>
			</view>
			<view class="bottom" @click="changannouncementStatus(item.announcementId)">
				<view class="">
					{{item.announcementTitle}}
				</view>
				<view class="title">
					{{item.announcementContent}}
				</view>
				<view class="foot">
					<text>查看详情</text>
					<u-icon name="arrow-right"></u-icon>
				</view>
			</view>
		</view>
		
	</view>
</template>

<script>
	import {
	  createNamespacedHelpers
	 } from 'vuex';
	 const {
	  mapActions,
	  mapState
	 } = createNamespacedHelpers('message');
	export default {
		async created(){
			//查询状态为所有的系统公告集合
			const a=await this.getAnnouncement()
			await this.getAnnouncementByAnnouncementStatus()
			this.getstatuo()
			this.xttells=a.data
		},
		data() {
			return {
				xttells:[]
			}
		},
		computed:{
			...mapState(['xitongtells'])
		},
		methods: {
			...mapActions(['getAllShowAnnouncement','updateAnnouncementStatusById','getAnnouncement','getAnnouncementByAnnouncementStatus']),
			//时间戳数据处理
			happenTimeFun(num){
			let date = new Date(num);
			//时间戳为10位需*1000，时间戳为13位的话不需乘1000
			        let y = date.getFullYear();
			        let MM = date.getMonth() + 1;
			        MM = MM < 10 ? ('0' + MM) : MM;//月补0
			        let d = date.getDate();
			        d = d < 10 ? ('0' + d) : d;//天补0
			        let h = date.getHours();
			        h = h < 10 ? ('0' + h) : h;//小时补0
			        let m = date.getMinutes();
			        m = m < 10 ? ('0' + m) : m;//分钟补0
			        let s = date.getSeconds();
			        s = s < 10 ? ('0' + s) : s;//秒补0
			        return y + '-' + MM + '-' + d + ' ' + h + ':' + m+ ':' + s;
			},
			//点击把未读变成已读
			async changannouncementStatus(announcementId){
			//console.log("announcementId",announcementId)
				// const data= await this.updateAnnouncementStatusById({announcementId:announcementId})
				// this.getstatuo()
			},
			// 返回之前的页面重新获取未读消息的数
			getstatuo(){
				// #ifdef MP-WEIXIN
				 let pages = getCurrentPages(); // 当前页面
				 let beforePage = pages[pages.length - 2]; // 前一个页面
				 beforePage.onLoad(); // 执行前一个页面的onLoad方法
				 // #endif
			},
			//下拉刷新
			async onPullDownRefresh() {
				console.log('refresh');
				// setTimeout(function () {
				//     uni.stopPullDownRefresh();
				// }, 1000);
				const a=await this.getAnnouncement()
				await this.getAnnouncementByAnnouncementStatus()
				this.getstatuo()
				this.xttells=a.data
				// this.getcaijinnews();
				// // this.getUserData();
				// this.userDetail();
				setTimeout(function() {
					uni.stopPullDownRefresh(); //停止下拉刷新动画
				}, 1000);
			}
		}
	}
</script>

<style lang="scss" scoped>
.box{
	background-color: #fafafa;
	height: 100vh;
	padding: 10rpx 25rpx;
	box-sizing: border-box;
	.box1{
		//background-color: #ffffff;
		margin-top: 30rpx;
		padding: 10rpx 25rpx;
		.top{
			background-color: #fafafa;
			text-align: center;
			text{
				border: 1px solid #f2f2f2;
				color: #f2f2f2;
				background-color: #c4c4c4;
				padding: 12rpx 10rpx;
				border-radius: 10rpx;
			}
		}
		.bottom{
			background-color: #ffffff;
			border-radius: 20rpx;
			margin-top: 40rpx;
			padding: 10rpx 25rpx;
			.title{
				font-size: 35rpx;
				font-weight: 500;
				padding: 30rpx 0rpx;
				border-bottom: 1px solid #f0f0f0;
			}
			.foot{
				padding: 10rpx 0;
				display: flex;
				justify-content: space-between;
				align-items: center;
				
			}
		}
	}
}
</style>
